package com.jinkaimen.kqb.ui.activity.h5toapp;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.bean.hss.OrderBean;
import com.jinkaimen.kqb.manager.ApiManager;
import com.jinkaimen.kqb.utils.QrcodeUtils;

import retrofit2.Call;
import retrofit2.Response;

public class QrcodeShowActivity extends BaseActivity {

    private TextView mTvActivityShopCollectionShopName;
    private TextView mTvActivityShopCollectionShopMoney;
    private RelativeLayout mRlActivityShopCollectionTaipai;
    private ImageView mIvActivityShopCollectionQrcode;
    private TextView mTvActivityUseMethod;
    private long ordernumber;
    private int channel;


    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {

        mTitleBarView.setTitleText("扫码收款");
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        ordernumber = callIntent.getLongExtra("ordernumber", -1);
        channel = callIntent.getIntExtra("channel", -1);

    }

    @Override
    protected int initContentView() {
        return R.layout.activity_shop_collection;
    }

    @Override
    protected void initChildView() {
        mTvActivityShopCollectionShopName = (TextView) findViewById(R.id.tv_activity_shop_collection_shop_name);
        mTvActivityShopCollectionShopMoney = (TextView) findViewById(R.id.tv_activity_shop_collection_shop_money);
        mRlActivityShopCollectionTaipai = (RelativeLayout) findViewById(R.id.rl_activity_shop_collection_taipai);
        mIvActivityShopCollectionQrcode = (ImageView) findViewById(R.id.iv_activity_shop_collection_qrcode);
        mTvActivityUseMethod = (TextView) findViewById(R.id.tv_activity_use_method);
    }

    @Override
    protected void initChildData() {
        showLoadingDialog();
        ApiManager.getApi().placerder(
                "HSS001043",
                ordernumber,
                channel
        ).enqueue(new NetCallBack<OrderBean>() {
            @Override
            protected void onSuccess(Call<OrderBean> call, Response<OrderBean> response) {
                if (response != null) {
                    OrderBean orderBean = response.body();
                    ViewGroup.LayoutParams layoutParams = mIvActivityShopCollectionQrcode.getLayoutParams();
                    Bitmap bitmap = QrcodeUtils.encodeAsBitmap(orderBean.payUrl, layoutParams.width, layoutParams.height);
                    mIvActivityShopCollectionQrcode.setImageBitmap(bitmap);
                    mTvActivityShopCollectionShopName.setText(orderBean.merchantName);
                    mTvActivityShopCollectionShopMoney.setText(orderBean.amount);
                    String orderName = "";
                    switch (orderBean.payMethod) {
                        case 1:
                            orderName = "微信";
                            break;
                        case 2:
                            orderName = "支付宝";
                            break;
                        case 4:
                            orderName = "QQ钱包";
                            break;
                    }
                    mTvActivityUseMethod.setText("请使用" + orderName + "扫码");
                }
            }

            @Override
            protected void hiddenProgress() {
                hideLodingDialog();
            }
        });
    }

    @Override
    protected void setChildViewListener() {
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);

    }

    //保存图片到系统相
}
